package com.xinhua.erp.controller;

import com.xinhua.erp.pojo.Account;
import com.xinhua.erp.pojo.Result;
import com.xinhua.erp.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("account")
@CrossOrigin
public class AccountController {

    @Autowired
    private AccountService accountService;


    @GetMapping("{id}")
    public Result findById(@PathVariable long id){
        return accountService.findById(id);
    }


    @GetMapping("{page}/{size}")
    public Result findAll(@PathVariable int page,@PathVariable int size){
        return accountService.findAll(page,size);
    }

    @GetMapping
    public Result findAll(){
        return accountService.findAll();
    }

    @DeleteMapping("{id}")
    public  Result deleteById(@PathVariable long id){
        return accountService.deleteById(id);
    }

    @PostMapping
    public Result save(@RequestBody Account account){
        return accountService.save(account);
    }

    @PutMapping("{id}")
    public Result update(@PathVariable Long id,@RequestBody Account account){
        return accountService.update(id,account);
    }

    @PostMapping("search/{page}/{size}")
    public Result Search(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size){
        return accountService.Search(searchMap,page,size);
    }
}
